import api from './api';
import { Agent } from '../types';

export const agentService = {
  getAgents: async (params?: { skip?: number; limit?: number; name?: string; category?: string }): Promise<Agent[]> => {
    const response = await api.get('/agents/', { params });
    return Array.isArray(response.data) ? response.data : response.data.items || [];
  },

  getAgent: async (id: number): Promise<Agent> => {
    const response = await api.get(`/agents/${id}`);
    return response.data;
  },

  createAgent: async (agent: Partial<Agent>): Promise<Agent> => {
    const response = await api.post('/agents/', agent);
    return response.data;
  },

  updateAgent: async (id: number, agent: Partial<Agent>): Promise<Agent> => {
    const response = await api.put(`/agents/${id}`, agent);
    return response.data;
  },

  deleteAgent: async (id: number): Promise<void> => {
    await api.delete(`/agents/${id}`);
  },
};
